package com.view

import androidx.annotation.ColorInt
import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel

/**
 * @describe:图形帮助类
 * @Author: lixiaopeng
 * @Date: 2020/11/10
 */
object ViewHelper {

    fun createShapeDrawable(corner: Float, @ColorInt tintColor: Int): MaterialShapeDrawable = MaterialShapeDrawable(
            ShapeAppearanceModel.builder()
                    .setAllCorners(CornerFamily.ROUNDED, corner)
                    .build()
    ).apply {
        setTint(tintColor)
    }

    fun createShapeDrawable(corner: Float,
                            @ColorInt tintColor: Int,
                            @ColorInt strokeColor: Int,
                            strokeWidth: Float) = MaterialShapeDrawable(
            ShapeAppearanceModel.builder()
                    .setAllCorners(CornerFamily.ROUNDED, corner)
                    .build()
    ).apply {
        setTint(tintColor)
        setStroke(strokeWidth, strokeColor)
    }

    fun createShapeDrawable(@ColorInt tintColor: Int,
                            topLeftCornerSize: Float,
                            topRightCornerSize: Float,
                            bottomLeftCornerSize: Float,
                            bottomRightCornerSize: Float) = MaterialShapeDrawable(
            ShapeAppearanceModel.builder()
                    .setTopRightCorner(CornerFamily.ROUNDED, topRightCornerSize)
                    .setTopLeftCorner(CornerFamily.ROUNDED, topLeftCornerSize)
                    .setBottomLeftCorner(CornerFamily.ROUNDED, bottomLeftCornerSize)
                    .setBottomRightCorner(CornerFamily.ROUNDED, bottomRightCornerSize)
                    .build()
    ).apply {
        setTint(tintColor)
    }

    fun createShapeDrawable(@ColorInt tintColor: Int,
                            @ColorInt strokeColor: Int,
                            strokeWidth: Float,
                            topLeftCornerSize: Float,
                            topRightCornerSize: Float,
                            bottomLeftCornerSize: Float,
                            bottomRightCornerSize: Float) = MaterialShapeDrawable(
            ShapeAppearanceModel.builder()
                    .setTopRightCorner(CornerFamily.ROUNDED, topRightCornerSize)
                    .setTopLeftCorner(CornerFamily.ROUNDED, topLeftCornerSize)
                    .setBottomLeftCorner(CornerFamily.ROUNDED, bottomLeftCornerSize)
                    .setBottomRightCorner(CornerFamily.ROUNDED, bottomRightCornerSize)
                    .build()
    ).apply {
        setTint(tintColor)
        setStroke(strokeWidth, strokeColor)
    }
}